interface Waiter {
    anjiao: boolean,
    say: () => {}
}

interface Teacher {
    anjiao: boolean,
    skill: () => {}
}

// animal 可能是两种类型（联合类型）
function judgeWho(animal: Waiter | Teacher) {
    if (animal.anjiao) {
        // 断言 animal 是 Teacher 类型
        (animal as Teacher).skill()
    } else {
        (animal as Waiter).say()
    }
}

function judgeWho2(animal: Waiter | Teacher) {
    if ("skill" in animal) {
        animal.skill()
    } else {
        animal.say()
    }
}

function add(first: string | number, second: string | number) {
    if (typeof first === "string" || typeof second === "string") {
        return `${first}${second}`
    }
    return first + second
}

class NumberObj {
    count: number;
}

function addObj(first: object | NumberObj, second: object | NumberObj) {
    if (first instanceof NumberObj && second instanceof NumberObj) {
        return first.count + second.count
    }
    return 0
}

console.log(1)
